<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
<!-- react 核心库 -->
<script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
<!-- dom相关库 -->
<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
<!-- Es6->Es5 jsx->js -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
 
<div id="app"></div>
<!-- 使用JSX，属性使用text/babel -->
<script type="text/babel">

    //1.创建组件
    class Weather extends React.Component{
        //初始化状态
        state = {
            isHot: false,
            wind: "微风"
        }

        render(){
            return(
                <h1 onClick={this.changeWeather}>今天天气很{this.state.isHot ? "炎热" : "凉爽"}，{this.state.wind}</h1>
            )
        }


        //自定义方法——要用赋值语句+箭头函数
        //复制语句放在了自身实例对象上，没有放在原型上
        changeWeather = () => {
            //箭头函数本身没有this，会找外一层的this
            console.log(this)
            const isHot = this.state.isHot
            this.setState({isHot: !isHot})
        }
    }

    

    //渲染组件
    ReactDOM.render(<Weather/>, document.getElementById("app"))
</script>
 
</body>
</html>